<div class="search">
  <div>
    <form method="get">
<!--       <button class="button-green" onclick="window.location='{:U(MODULE_NAME.'/Product/add')}'">添加产品</button> -->
    <input type="text" name="keyword" class="input-m" value="{$keyword}" id="keywords" placeholder="请输入产品ID或者名称">
    <input type="submit" class="button-green" value="查  询" id="keyword">
    </form>
  </div>
  <!-- <div class="button-green file-btn" onclick="KD.click()" style="margin-left:20px;">导入产品上架表
  <form id="uploadKD" action="/Home/Product/importKD" method="post" enctype="multipart/form-data">
  <input id="KD" type="file" name="KD">
  </form>
  </div> -->
</div>


<!-- <div class="operate2">
  <ul>
    <li onclick="window.location='{:U(MODULE_NAME.'/Product/add')}'"><span class="icon-add01"></span>添加产品</li>
    <li class="file-btn"><span class="icon-import01"></span>导入产品上架表
      <form id="uploadKD" action="/Home/Product/importKD" method="post" enctype="multipart/form-data">
      <input id="KD" type="file" name="KD">
      </form>
    </li>
  </ul>
  <div class="clear"></div>
</div> -->

<table class="list">
		<thead>
		<tr>
	        <th>产品ID</th>
	        <th>图片</th> 
	        <th>标题</th>
	        <th>分类</th>
            <th>供应商</th>
	        <th>发布时间</th>
	        <th>操作</th>
      	</tr>
		</thead>
         <tbody>
		<foreach name='list' item='v'>
        <tr>
           <td>{$v.id}</td>
            <td>
              <img src="<if condition='$v.litpic eq null'>__PUBLIC__/image/product.jpg<else/>__URL__{$v.litpic}</if>" width="220" />
           </td> 
           <td class="title" >{$v.title}<if condition="$v.recommend eq 1"><span style="color:#FF0000;">[今日推荐]</span></if></td>
           <td>
           		<foreach name="v.category" item="cate" >
                {$cate}||
              	</foreach>
            </td>
           <td>{$v.supplier}</td>
           <td>{$v.dateline}</td>
           <td width="">
               <if condition="$v.recommend eq 1">
                <a href="javascript:;" onclick="toConfirm('{:U(MODULE_NAME.'/Product/recommendout',array('id' => $v['id']), '')}', '确实要取消推荐吗？')">取消推荐</a>&nbsp;
               <else />
               <a href="javascript:;" onclick="toConfirm('{:U(MODULE_NAME.'/Product/recommendin',array('id' => $v['id']), '')}', '确实要推荐吗？')" class="red">今日推荐</a>&nbsp;
               </if>
               <a href="__URL__/Product/details/id/{$v['id']}" target="_blank">查看</a>&nbsp;
               <a href="{:U(MODULE_NAME.'/Product/edit',array('id' => $v['id']), '')}">编辑</a>&nbsp;
               <a href="javascript:" onclick="Down('{$v['id']}','{$v['title']}')">下架</a>&nbsp;
               <a href="javascript:;" onclick="toConfirm('{:U(MODULE_NAME.'/Product/del',array('id' => $v['id']), '')}', '确实要删除吗？')">删除</a>
           </td>
       </tr>
      </foreach>
 </tbody>
</table>
<div class="page" style="clear: both;">{$page}</div>
<script type="text/javascript">
$(function(){
    $("#KD").change(function(){
		$("#uploadKD").submit();
	});
});

function Down(id,title)
{
	var Div = layer.open({
		type: 1,
	    title: '产品上架',
	    area: ['450px', '180px'],
	    shift: 0,
	    content: '你现在下架的是：'+title+'</p><p>是否下架该产品？',
	    btn:['确定','取消'],
	    yes: function(index){
	    	window.location.href = "/Home/Product/marketout/id/"+id;
	    }, 
	    cancel: function(){
	    	layer.close(Div);
	    }
	});
}

//取得所有CSS样式为 ".title" 的对象，并对默认自定义的方法进行遍历操作

$(".title").each(function(){

    //取得标签的文本

    var t = $(this).text();



    //获取关键字

    var keywords =$('#keywords').val();



    //取得需要查出的关键字，我们这里假定是多关键字以","间隔

    var array = (keywords).split(",");



    //开始用关键字遍历标签文本

    for(var i=0;i<array.length;i++){



        //判断标签是否包含关键字

        if(t.indexOf(array[i])>-1){



         //定义正则表达式对象  array[i]是关键字   "g"是指全局范围

         var a = new RegExp(array[i],"g")



         //对标签文本进行全局替换，包含关键字的位置替换为加红字span对象

         t = t.replace(a,("<span style='color:red; font-weight: bold; '>" + array[i] + "</span>"));



         //将替换完的文本对象赋给此对象中A标签对象的html值中

         $(this).html(t);

        }

    }

});

</script>